var oldDescription = "";
//ดึงข้อมูล text editor มาใช้งาน
function getFormat_Onload(){
	CKEDITOR.replace( 'contacts_txtaDescription',{
    	skin   : 'kama', //กำหนดรูปแบบหน้าตา
    	height   : 670, //กำหนดความสูง
    	width    : 795,//กำหนดความกว้าง
    	toolbar :
    	[
    	['Undo','Redo','-','Find','Replace','-'],
    	['Font','FontSize'],
    	['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    	['RemoveFormat'],
    	
    						'/',
    	['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
    	['TextColor','BGColor'],
    	['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
    						'/',
    	['Image','Flash','MediaEmbed','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
    	['Link','Unlink','Anchor'],
    	['Maximize', 'ShowBlocks','-','About']
    	],
    	filebrowserBrowseUrl : 'js/ckfinder/ckfinder.html',
    	filebrowserImageBrowseUrl : 'js/ckfinder/ckfinder.html?type=Images',
    	filebrowserFlashBrowseUrl : 'js/ckfinder/ckfinder.html?type=Flash',
    	filebrowserUploadUrl : 'js/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
    	filebrowserImageUploadUrl : 'js/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
    	filebrowserFlashUploadUrl : 'js/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
    });
}	
//ส่ง email
function contactsView_sendEmail(id)
{	
	if(document.getElementById("contact_view_txtTo").value == "")
	{
		alert("กรุณากรอก email ผู้รับ");
		return false;
	}
	else if(document.getElementById("contact_view_txtSubject").value == "")
	{
		alert("กรุณากรอกหัวข้อที่ส่ง");
		return false;
	}
	else if(document.getElementById("contacts_txtaDescription").value == "")
	{
		alert("กรุณากรอกรายละเอียดที่ส่ง");
		return false;
	}
	else
	{
		document.getElementById("contacts_id").value = id;
		document.getElementById("contacts_to").value = document.getElementById("contact_view_txtTo").value;
		document.getElementById("contacts_cc").value = document.getElementById("contact_view_txtCc").value;
		document.getElementById("contacts_bc").value = document.getElementById("contact_view_txtBc").value;
		document.getElementById("contacts_subject").value = document.getElementById("contact_view_txtSubject").value;
		document.getElementById("contacts_description").value = CKEDITOR.instances.contacts_txtaDescription.getData().replace(/\'/g,"\\'");		
		document.forms["formSubmit"].submit();
	}
}
//ยกเลิกการส่ง 
function contacts_Delete(id,title)
{
	if(confirm("ต้องการลบรายการ \""+title+"\" ใช่หรือไม่?"))
		window.location = "command/rawdata/deleteContacts.php?contacts_id="+id;	
}
//reply email
function contactsView_emailReply(date)
{
	oldDescription =  CKEDITOR.instances['contacts_txtaDescription'].getData().replace(/\'/g,"\\'");
	document.getElementById("replyForm").style.display = '';
	$replyHead = "_____________________________________________________<br/>"
	$replyHead += "<p>"+date+" &lt;<span style=\"color:#daa520;\"><u>"+document.getElementById("contact_view_txtTo").value+"</u></span>&gt;</p>";
	var description = "<span style=\"color:#800080;\">"+oldDescription+"</span>";
	CKEDITOR.instances['contacts_txtaDescription'].setData( $replyHead+description, function()
    {
        this.checkDirty();  // true
    });
}
//calcel reply
function contactsView_cancelReply()
{
	CKEDITOR.instances['contacts_txtaDescription'].setData( oldDescription, function()
    {
        this.checkDirty();  // true
    });
	document.getElementById("replyForm").style.display = 'none';
}
//fwd email
function emailForward(date)
{
	var forwardHead = "---------- Forwarded message ----------<br/>"+
	"From: "+document.getElementById("contact_view_txtTo").value+" <$to><br/>"+
	"Subject: "+document.getElementById("contact_view_txtSubject").value+"<br/>"+
	"To: formantailor@gmail.com<br/><br/>";
}